

function EditDragSource(dom, sensor) {
  EditDragSource._super.call(this, dom, sensor);
}
Object.extend("EditDragSource", "E.DragSource");

EditDragSource.prototype.createDrag = function(anchorV) {
  return new EditDragView(this, anchorV);
}


function EditDragView(dragSource, anchorV) {
  EditDragView._super.call(this, dragSource, anchorV);
}
Object.extend("EditDragView", "E.DragView");

EditDragView.prototype.onDragStart = function(evn) {
	EditDragView._super.prototype.onDragStart.call(this, evn);
	this.dom.element.style.backgroundColor = "#DDDDFF";
	this.dom.setOpacity(0.3);
	this.draft.element.style.backgroundColor = "#CCCCEE";
	this.draft.setOpacity(0.8);
	this.draft.show();
	this.source.box.setOpacity(0.3);
}

EditDragView.prototype.onDrag = function(v, evn) {
  return true;
}

EditDragView.prototype.onDrop = function(v, evn) {
  var e = this.draft.element;
  var d = this.source.box.element;
  e.parentNode.replaceChild(d, e);
  this.source.box.setOpacity(1.0);
  this.source.box.show();
  return true;
}

EditDragView.prototype.onCancel = function(evn) {
  this.source.box.setOpacity(1.0);
  this.source.box.show();
  return true;
}


EditDropTarget = function(dom) {
  dom.onDragOver = function(evn) {
  	if (evn.dropTargetLevel == 0) {
  	  this.style.backgroundColor = "#EEEEEE";
		  evn.dragView.draft.show();
  	  var r = null;
  	  var sV = Dom(this).getScrollVector();
  	  var eV = [evn.clientX + sV[0], evn.clientY + sV[1]];
		  for (var i = 0; i < this.childNodes.length; ++i) {
		    var n = this.childNodes[i];
		    if (!n.onDropInto)
		      continue;
		    var v = Dom(n).getVector();
		    var d = eV[1] - v[1] - (n.offsetHeight / 2);
		    if (d < 0) {
		      r = n;
		      if (n == evn.dragView.source.box.element)
		        evn.dragView.draft.hide();
		      break;
		    }
		  }
  	  this.insertBefore(evn.dragView.draft.element, r);
  	}
  	else {
    	this.style.backgroundColor = "";
  	}
  };
  dom.onDragOut = function(evn) {
  	this.style.backgroundColor = "";
  };
  dom.onDropInto = function(evn) {
  	this.style.backgroundColor = "";
  	if (evn.dropTargetLevel > 0)
  	  return;
    var t = Dom(this).getEntityView();
    var s = Dom(evn.dragView.source.box.element).getEntityView();
    //var a = new MoveIntoAction(t.entity, s.entity, evn.ctrlKey);
    //a.perform();
    //a.close();
    alert(t.entity.getId());
  };
}

